﻿<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.util.*,org.yoao.crm.acl.ACLTool,org.yoao.crm.tools.PubFunction,org.yoao.crm.dao.UserDAO,org.yoao.crm.bean.StaticBean"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	String userName = request.getParameter("userName");
	org.yoao.crm.bean.Session httpSession = (org.yoao.crm.bean.Session)session.getAttribute("userSession");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>请选择数据</title>
<jsp:include page="../public/publicJs.jsp" flush="false"></jsp:include>
<script language="javascript">
function getSelectValue(){
	var objSelect = document.getElementById("datalist");
	var value = "";
	for(i=0;i<objSelect.length;i++){
		if(objSelect.options[i].selected){
			value = objSelect.options[i].value;
			break;
		}
	}
	window.returnValue = value;
	window.close();
}
function cancelRole(){
	window.returnValue = "CANCELUSER";
	window.close();
}
function searchSubmit(){
	document.all.searchbar.submit();
}
</script>
</head>
<base target="_self"/>
<body>
<div id="cwMain">
<table width="100%" height="20" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td  valign="top">
<form id="searchbar" name="searchbar" action="datawindowUser.jsp" method="post">
<table  id="title_top" border="0" cellspacing="0" cellpadding="0" width="100%" >
	<tr  class="tree_title_txt">
        <td nowrap align="right"  class="tree_title_txt">
                                用户名称: <input type="text" name="userName" value="<%=userName!=null?userName:""%>" style="width:90px">
            <image src="<%=basePath%>images/tbtn_searh.gif" alt="查询" align="absmiddle" style="cursor:hand" onClick="searchSubmit()"/></td>
    </tr>
</table>
</form>
<%
String sql = null;
if(ACLTool.isAdmin(httpSession.getRoleId())){
	sql = "select USERNAME, NICKNAME from baseuser where ROLEID <> '"+StaticBean.ROLE_ADMIN+"'";
	if(userName != null && !userName.trim().equals("")) sql += " and NICKNAME like'%"+userName+"%'";
}else{
	sql = "select baseuser.username, baseuser.nickname from baseuser " +
		  "left join userRole on baseuser.roleId = userRole.roleId " +
		  "where userRole.parentId='"+httpSession.getRoleId()+"' ";
	if(userName != null && !userName.trim().equals("")) sql += " and baseuser.NICKNAME like'%"+userName+"%'";
}
List list = new UserDAO().queryMultiColumn(sql);
%>
<select name="datalist" size="21" style="width:100%" ondblclick="getSelectValue()">
<option selected></option>
<%if(userName == null || userName.trim().equals("")){ %>
<option value="<%=httpSession.getUserName()%>|<%=httpSession.getNickName()%>"><%=httpSession.getNickName()%></option>
<%}%>
<%
if(list != null){
	int size = list.size();
	for(int i=0;i<size;i++){
		Map map = (Map)list.get(i);
		String accessSno = (String)map.get("USERNAME");
		String accessName = (String)map.get("NICKNAME");
		accessSno = accessSno + "|" + accessName;
%>
		<option value="<%=accessSno%>"><%=accessName%></option>
<%
	}
}
%>
</select>
</td>
</tr>
<tr>
   <td align="center" height="30">
   	<input class="com_button" type="button" value="确定" onClick="getSelectValue();">
   	<input class="com_button" type="button" value="取消" onClick="cancelRole();">
   </td>
</tr>
</table>
</div>
</body>
</html>